package com.yxzx.ebs.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxzx.common.YxzxResult;
import com.yxzx.ebs.entity.EbsCourse;
import com.yxzx.ebs.entity.EbsTeacher;
import com.yxzx.ebs.service.EbsCourseService;
import com.yxzx.ebs.service.EbsTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Copyright (C), 2018-2020
 * FileName: EbsFrontTeacherController
 * Author:   kongfanyu
 * Date:     2020/8/17 00:08
 */
@Api(tags = "讲师管理前台业务控制器")
@RestController
@CrossOrigin
@RequestMapping("/eduservice/front/teacher")
public class EbsFrontTeacherController {
    @Autowired
    private EbsTeacherService teacherService;
    @Autowired
    private EbsCourseService courseService;

    @ApiOperation(value = "分页查询讲师")
    @GetMapping("{page}/{limit}")
    public YxzxResult getPageList(@ApiParam(name = "page",value = "当前页",required = true) @PathVariable Long page,
                                  @ApiParam(name = "limit",value = "每页大小",required = true) @PathVariable Long limit){
        IPage<EbsTeacher> teacherIPage = teacherService.page(new Page<>(page, limit), null);
        return YxzxResult.ok().data("items",teacherIPage);
    }

    @ApiOperation(value = "根据ID查询讲师详情及授课信息")
    @GetMapping("{teacherId}")
    public YxzxResult getById(@ApiParam(name = "teacherId",value = "讲师ID",required = true) @PathVariable String teacherId){
        //1.查询讲师详情
        EbsTeacher teacher = teacherService.getById(teacherId);
        //2.查询讲师授课列表
        QueryWrapper<EbsCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",teacherId);
        List<EbsCourse> courseList = courseService.list(queryWrapper);
        return YxzxResult.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
